package com.treasure.mall.biz.base;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/8/22
 */
public class ExportPageRequest extends PageRequest {
    private int pageSize;

    public ExportPageRequest(int page, int size) {
        super(page, size);
    }

    public ExportPageRequest(int page, int size, Sort.Direction direction, String... properties) {
        super(page, size, direction, properties);
    }

    public ExportPageRequest(int page, int size, Sort sort) {
        super(page, size, sort);
    }

    public static ExportPageRequest of(int beginPage, int pageCount, int pageSize, Sort sort) {
        ExportPageRequest pageRequest = new ExportPageRequest(beginPage, pageCount * pageSize, sort);
        pageRequest.pageSize = pageSize;
        return pageRequest;
    }

    @Override
    public long getOffset() {
        return super.getPageNumber() * this.pageSize;
    }
}
